package com.tongchengsoft.filter;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

public class ParamsFilter implements Filter {

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {

		HttpServletRequest request = (HttpServletRequest) req;
		String realPath = request.getRequestURI();
		System.out.println("realPath:" + realPath);
		if (realPath.endsWith(".html") || realPath.endsWith(".htm") || realPath.endsWith(".css") || realPath.endsWith(".jpg") || realPath.endsWith(".gif") || realPath.endsWith(".js") || realPath.endsWith(".png") || realPath.endsWith(".ico") || realPath.endsWith(".swf")) {
			chain.doFilter(req, resp);
		} else {
			Map<String, String[]> m = new HashMap<String, String[]>(req.getParameterMap());
			req = new ParameterRequestWrapper(request, m);
			chain.doFilter(req, resp);
		}
	}

	@Override
	public void destroy() {
	}

}
